using MySqlConnector;

namespace Front._1127;

public partial class Login : Form
{
    public Login()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        using var connection = new MySqlConnection("server=localhost;port=3306;database=book;user=root;password=123456;charset=utf8mb4;AllowPublicKeyRetrieval=True;");
        connection.Open();
        string sql = "SELECT* FROM admin_info where admin_account= @account and admin_password= @pwd;";

        using var command = new MySqlCommand(sql, connection);
        string account = this.textBox1.Text;
        string password = this.textBox2.Text;
        string pwd=MD5Helper.GetMD5(password);
        command.Parameters.AddWithValue("@account", account);
        command.Parameters.AddWithValue("@pwd", pwd);
        
        
        using var reader = command.ExecuteReader();
        if (reader.HasRows)
        {
            //登陆成功，跳转主窗体
            Mainform mainform = new Mainform();
            mainform.Show();
            //隐藏登陆窗体
            this.Hide();
        }
        else
        {
            //登陆失败
            MessageBox.Show("账号或密码错误");
            this.textBox1.Text = "";
            this.textBox2.Text = "";
        }
       
    }

    private void Login_Load(object sender, EventArgs e)
    {
        this.textBox1.Text = "admin_super01";
        this.textBox2.Text = "123456";
    }
}